﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace ODM_Code.Code
{
    public class AlternativeSetupCode
    {
        public AlternativeSetupCode()
        {
        }

        public void CopyNeededFiles(string dbfPath, string inputPath, string alternativepPath)
        {

        }

        public int CountFires(string inputPath)
        {
            string[] files = System.IO.Directory.GetFiles(inputPath, "inputfile*");
            return files.Length;
        }

        public List<string> GetExistingAlternatives(string inputPath)
        {
            List<string> alternatives = new List<string>();

            string[] files = System.IO.Directory.GetDirectories(inputPath);
            foreach (string s in files)
            {
                string[] spl = s.Split('\\');
                int i = spl.Length;

                string addThis = spl[i - 1];
                if (addThis.StartsWith("S"))
                {
                    alternatives.Add(addThis);
                }
            }

            return alternatives;
        }

        public int GetNextAvailableAlternativeNumber(string inputPath)
        {
            string[] existingdirectories = Directory.GetDirectories(inputPath, "S*");
            return existingdirectories.Length + 1;
        }

        public void WriteParametersFile(string inputPath, string resultsPath, string intensity, string clustersize, int numberOfFires)
        {
            if (resultsPath == null)
            {
                resultsPath = inputPath + "\\results";
            }

            if (!Directory.Exists(resultsPath))
            {
                Directory.CreateDirectory(resultsPath);
            }

            StreamWriter sw = new StreamWriter("C:\\magfire\\main\\parameters.txt");
            sw.AutoFlush = true;
            sw.WriteLine("INFOLDER\tOUTFOLDER\tNREPS\tNITERS\tETEMP\tCOOLTH\tPENALTY\tINTENSITY\tCLUST_SIZE\tNUM_FIRES\t");

            string line =
                inputPath + "\t" +
                resultsPath + "\t" +
                "10" + "\t" +
                "50" + "\t" +
                "1" + "\t" +
                "0.990" + "\t" +
                "100000.0" + "\t" +
                intensity + "\t" +
                clustersize + "\t" +
                numberOfFires.ToString();

            sw.WriteLine(line);
            sw.Close();
        }
    }
}
